package com.example.appdemo1.service.imp;

import com.example.appdemo1.entity.Page;
import com.example.appdemo1.entity.Shop;
import com.example.appdemo1.mapper.ShopMapper;
import com.example.appdemo1.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class ShopServiceImp implements ShopService {
    @Autowired
    private ShopMapper shopMapper;
    @Override
    public Page findShopByPage(int currPage, int pageSize) {
        Page page = new Page();//封装分页数据
        List<Shop> shopList = new ArrayList<Shop>();
        page.setCurrPage(currPage);
        int startNum = (currPage-1)*pageSize;
        //查询分页显示数据
        List<Shop> list = shopMapper.findShopByPage(startNum,pageSize);
        for (Shop shop:list) {
            if (shop.getIsCollect() == 1){
                shopList.add(shop);
            }
        }
        System.out.println(list.size());
        page.setList(shopList);
        //查询总记录数
        int totalCount = shopMapper.findAllCount();
        page.setCount(totalCount);
        int totalPage = (int) Math.ceil(totalCount/(pageSize*1.0));
        page.setTotalPage(totalPage);
        return page;
    }
}
